<?php
	include ("status.php");

	$query  = "SELECT * from users where id='" . $id . "'";
	$result = mysql_query($query);
  $profileinfo = mysql_fetch_array($result);


	if ($profileinfo['status'] & $STA_ADMIN) {
		if ($_REQUEST['admindo']=='news'){
			include("adminnews.php");
		} else 
		if ($_REQUEST['admindo']=='banner'){
			include("adminbanner.php");
		} else 
		if ($_REQUEST['admindo']=='users') {
			if ($_REQUEST['update']) {
				$userid = escapestr($_REQUEST['id']);
				$status = 0 ;
				if ($_REQUEST['ismember']) 	$status |= $STA_MEMBER;			
				if ($_REQUEST['isbanned']) 	$status |= $STA_BANNED;
				if ($_REQUEST['isadmin']) 	$status |= $STA_ADMIN;
				if ($_REQUEST['ismod']) 		$status |= $STA_MOD;
				if ($_REQUEST['isdj']) 			$status |= $STA_DJ;
				if ($_REQUEST['istrans']) 	$status |= $STA_TRANS;
				if ($_REQUEST['isband']) 		$status |= $STA_BAND;
				if ($_REQUEST['isold']) 		$status |= $STA_OLD;
				if ($_REQUEST['ispay']) 		$status |= $STA_PAY;
				if ($_REQUEST['isere']) 		$status |= $STA_ERE;
				if ($_REQUEST['iscoder']) 	$status |= $STA_CODER;
				$query = "update `users` set `status` = '$status'  where `id`='$userid'"; 
				$result = mysql_query ($query) ; 
				if ($result) {
					$query = "select * from `radio_dj` where `userid`='$userid'"; 
					$result = mysql_query ($query) ; 
					if (!(mysql_num_rows($result))) {
						if ($_REQUEST['isdj']) {	
						$query = "insert into `radio_dj` (`userid`) values ('$userid')"; 
						$result = mysql_query ($query) ; 
						}
					} else {
						if (!($_REQUEST['isdj'])) {
							$query = "select * from `radio_dj` where `userid`='$userid'"; 
							$result = mysql_query ($query) ; 
							$radio = mysql_fetch_array($result);
							$djid = $radio['id'];
							$query = "delete from `radio_dj` where `userid`='$userid'"; 
							$result = mysql_query ($query) ; 
							$query = "delete from `radio_show` where `dj`='$djid'"; 
							$result = mysql_query ($query) ; 
							$query = "delete from `radio_exception` where `dj`='$djid'"; 
							$result = mysql_query ($query) ; 
							$query = "delete from `radio_extra` where `dj`='$djid'"; 
							$result = mysql_query ($query) ; 
							$query = "delete from `radio_weekly` where `dj`='$djid'"; 
							$result = mysql_query ($query) ; 
						}		
					}
					$SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_member"),GetLangString($lang,"msg_userupdated"));
				} else {	
					$SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_error"),GetLangString($lang,"msg_dberror"));
				}
			}
			$query        = "SELECT * from users";
			$result = mysql_query($query);
			if (mysql_num_rows($result)){ 
			$profiles = "<table border=1 width=\"90%\">";
				while ($profileinfo = mysql_fetch_array($result)){
					$ISMEMBER = ( $profileinfo['status'] & $STA_MEMBER ) ? 'checked' : false;
					$ISBANNED = ( $profileinfo['status'] & $STA_BANNED ) ? 'checked' : false;

					$ISADMIN 	= ( $profileinfo['status'] & $STA_ADMIN ) ? 'checked' : false;
					$ISMOD 		= ( $profileinfo['status'] & $STA_MOD ) ? 'checked' : false;

					$ISDJ			= ( $profileinfo['status'] & $STA_DJ ) ? 'checked' : false;
					$ISCODER 	= ( $profileinfo['status'] & $STA_CODER ) ? 'checked' : false;
					$ISTRANS	= ( $profileinfo['status'] & $STA_TRANS ) ? 'checked' : false;
					$ISBAND 	= ( $profileinfo['status'] & $STA_BAND ) ? 'checked' : false;
					
					$ISOLD 		= ( $profileinfo['status'] & $STA_OLD ) ? 'checked' : false;
					$ISPAY 		= ( $profileinfo['status'] & $STA_PAY ) ? 'checked' : false;
					$ISERE 		= ( $profileinfo['status'] & $STA_ERE ) ? 'checked' : false;



					$status = GetStatusImg($profileinfo['status']);
					$img = "/index.php?do=getphoto&id=".$profileinfo['photo']."&size=75&square=1";			
					//$img = "images/sheep.png";
					$pid = $profileinfo['id'];
					$profiles .= "<tr><td width=\"100\"><div class=\"userthumb\">
										<a href=\"/index.php?do=profile&profile_id=".$profileinfo['id']."\">												
										".$profileinfo['name']."</a><br>$status<br><img src=\"$img\" title=\"$TXT_NOIMG\" 
												width=\"75\" height=\"75\"></div></td><td valign=\"top\">
												<!-- table within table, is it allowwed??? who cares!! -->
												<form method=\"post\" action=\"index.php?do=admin&admindo=users\">
												<table border=\"1\" width=\"100%\">
													<tr>
														<td><input type=\"checkbox\" $ISMEMBER 	name=\"ismember\">"	.GetLangString($lang,"txt_member")."</td>
														<td><input type=\"checkbox\" $ISBANNED 	name=\"isbanned\">"	.GetLangString($lang,"txt_banned")."</td>
														<td><input type=\"checkbox\" $ISADMIN 	name=\"isadmin\">"	.GetLangString($lang,"txt_admin")."</td>
														<td><input type=\"checkbox\" $ISMOD 		name=\"ismod\">"		.GetLangString($lang,"txt_mod")."</td>
													</tr>
													<tr>
														<td><input type=\"checkbox\" $ISDJ 			name=\"isdj\">"			.GetLangString($lang,"txt_dj")."</td>
														<td><input type=\"checkbox\" $ISCODER 	name=\"iscoder\">"	.GetLangString($lang,"txt_coder")."</td>
														<td><input type=\"checkbox\" $ISTRANS 	name=\"istrans\">"	.GetLangString($lang,"txt_translater")."</td>
														<td><input type=\"checkbox\" $ISBAND 		name=\"isband\">"		.GetLangString($lang,"txt_band")."</td>
													</tr>
													<tr>
														<td><input type=\"checkbox\" $ISOLD 		name=\"isold\">"		.GetLangString($lang,"txt_old")."</td>
														<td><input type=\"checkbox\" $ISPAY 		name=\"ispay\">"		.GetLangString($lang,"txt_pay")."</td>
														<td><input type=\"checkbox\" $ISERE 		name=\"isere\">"		.GetLangString($lang,"txt_ere")."</td>
														<td><input type=\"submit\" name=\"update\" value=\"".GetLangString($lang,"txt_save")."\"</td>
													</tr>
												</table>
												<input type=\"hidden\" name=\"id\" value=\"$pid\"></form>												
												</td></tr>";
				}
			$profiles .= "</table>";
			$SITE_MIDDLE .= FormatElement ( GetLangString($lang,"txt_profiles"),$profiles);
			}
		} else 
		{
			$SITE_MIDDLE .=  FormatSmallElement ( GetLangString ($lang, "txt_adminpanel") , 	
		"<center><table border=\"0\" width=\"75%\"><tr><td align=\"center\" valign=\"top\" width=\"50%\">". 
		FormatLink(GetLangString($lang,"txt_managenews"),	GetLangString($lang,"msg_managenews"),		"index.php?do=admin&admindo=news").
		FormatLink(GetLangString($lang,"txt_manageusers"),	GetLangString($lang,"msg_manageusers"),	"index.php?do=admin&admindo=users").
		"</td><td align=\"center\"  valign=\"top\">".				
		FormatLink(GetLangString($lang,"txt_modpanel"),	GetLangString($lang,"msg_modpanel"),	"index.php?do=mod").
 FormatLink(GetlangString($lang,"txt_bannerpanel"),GetlangString($lang,"msg_bannerpanel"), "index.php?do=admin&admindo=banner") .
		"</td></tr></table></center>");
	}
} else {
		$SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_noadminerror"),GetLangString($lang,"msg_noadminerror").$profileinfo['status']);
}

?>
